﻿import { Book } from './book.model'
import { dataSource } from './dataSource.model';

export class BookRepository{
  private dataSource : dataSource;
  private readonly books : Book[];

  constructor() {
    this.dataSource = new dataSource();
    this.books = new Array<Book>();
    this.dataSource.getBooks().forEach(b=>this.books.push(b));
    console.log(this.books);
  }

  getBooks():Book[]{
    return this.books;
  }

  getBookId(id:number): Book  {
     // @ts-ignore
    return this.books.find(b=> b.id == id);
  }

}
